#include "conversevoicemessage.h"
#include "converseabstractconversation.h"

#include <QFile>


namespace Converse {

VoiceMessage::VoiceMessage(qint64 id,
                           qint64 localId,
                           const AbstractConversation &conversation,
                           qint64 createdTime,
                           qint64 receivedTime,
                           int32_t senderId,
                           qint64 receiverId,
                           const QString &voiceUrl,
                           QObject *parent)
    : Converse::AbstractMessage(id,
                        localId,
                        conversation,
                        createdTime,
                        receivedTime,
                        senderId,
                        receiverId,
                        parent)
    , m_url(voiceUrl)
{
    m_tempFile = "";
    m_isAccepted = false;
    m_isRejected = false;
    m_isCancel = false;
}


VoiceMessage::~VoiceMessage()
{
    if (!m_tempFile.isEmpty())
        QFile::remove(m_tempFile);
}


const QString &VoiceMessage::message() const
{
    return m_textMessage;
}


AbstractMessage::Type VoiceMessage::type() const
{
    return AbstractMessage::VoiceType;
}


QVariant VoiceMessage::extra() const
{
    QVariantMap map;
    map.insert("voiceId", voiceId());
    return map;
}


void VoiceMessage::setAcceptedState()
{
    m_isAccepted = true;
    m_isRejected = false;
    m_isCancel = false;
}


void VoiceMessage::setRejectState()
{
    m_isAccepted = false;
    m_isRejected = true;
    m_isCancel = false;
}


void VoiceMessage::setCancelState()
{
    m_isAccepted = false;
    m_isRejected = false;
    m_isCancel = true;
}

} // namespace Converse
